$def with(form, posts, pager)
$:render.admin.header(scripts=['scripts/libs/jquery.tools.min.js','scripts/libs/fancybox/jquery.fancybox-1.3.4.pack.js','admin/scripts/core.js'],css=['admin/css/ui.css','scripts/libs/fancybox/jquery.fancybox-1.3.4.css'])

<script type="text/javascript">
    $$(function () {
        // 初始化fancybox
        $$('._fancybox').fancybox({
                'autoScale': true,
                'type': 'iframe',
                'width': 670,
                'height': 388
        });
        // 初始化日期控件
        $$(':date').dateinput({
            onHide: function() { return false; },
            format: 'yyyymmdd'
        }).data('dateinput').setValue(0).show();
        // 选中项容器显示
        $if form.discount_info_html.value:
            $$('#sel_container').show();

        $$('.dispatch').click(function () {
            if (!confirm('确定现在发送订阅邮件吗？（请确定后，不要重复点击发送按钮）')) {
                return false;
            }
            $$.post('$config.ADMIN_DIR/discount/top10/dispatch'
                , function (response) {
                    if (response == '0') {
                        alert('订阅邮件请求已发送，订阅用户将陆续收到订阅邮件，如发现有漏发情况，可稍等几分钟后，再次点击发送按钮。');
                        return true;
                    }
                
            });
        });
    });
    
    var selected = [];
    function top10_selected(value, mode) {
        if (value) {
            if (mode == 'add')
                selected.push(value);
            else
                selected.removeBy(value);
            top10_selected_values(selected);
        }
    };
    // TOP 10 选择
    function top10_selected_values(values) {
        var idvals = [], titvals = [];
        var lstEL = $$('#sel_list');
        // 删除以前的选择
        lstEL.find('dd').remove();
        $$.each(values, function (index, val) {
            var vals = val.split('|');
            idvals.push(vals[0]);
            titvals.push('<dd related="'+vals[0]+'">—&nbsp;<a href="/discounts/'+vals[0]+'" target="_blank">' + vals[1] + '</a></dd>');
        });
        $$('#discount_info_ids').val(idvals.join(','));
        $$('#sel_container').show();
        lstEL.append($$(titvals.join('')));
        $$('#sel_len').html('已选择：<strong>' + idvals.length + '</strong> 项');
        //$$.fancybox.close();
    };
    // 已经选择得数据
    function selected_values() {
        // 这里重置已选数据
        // 重新选择一次
        selected = [];
        var retvals = [];
        $$('#sel_list dd').each(function () {
            var el = $$(this);
            retvals.push(el.attr('related'));
            selected.push(el.attr('related') + '|' + el.find('a').html());
        });
        return retvals;
    };
</script>

<div class="itemtitle">
    <h3>甄选TOP30</h3>
</div>

<table class="tb tb2">
    <tr>
        <td class="noborder vtop" width="450">
            <form method="post">
            <table class="tb tb2">
                <tr><th><strong>$:form.submit.attrs['html']</strong></th></tr>
                <tr><td class="td27">日期</td></tr>
                <tr>
                    <td class="vtop rowform" height="380" width="400">
                        $:form.date.render()
                    </td>
                </tr>
                <tr><td class="td27">包含特惠信息</td></tr>
                <tr>
                    <td class="vtop rowform">
                        $:form.discount_info_ids.render()
                        <div id="sel_container" style="display:none;">
                            <dl id="sel_list" class="normal">
                                $if form.discount_info_html.value:
                                    $:form.discount_info_html.value
                                $else:
                                    <dt id="sel_len"></dt>
                            </dl>
                            <br />
                        </div>
                        <a href="$config.ADMIN_DIR/discount?mode=lite" class="_fancybox">选取特惠信息</a>
                    </td>
                </tr>
                <tr>
                    <td>$:form.submit.render()</td>
                </tr>

            </table>
            </form>
        </td>
        <td class="vtop">
            <table class="tb tb2">
                <tr>
                    <td colspan="3" align="right"><input type="button" value="发送 Top10 订阅邮件" class="btn dispatch" /></td>
                </tr>
                <tr>
                    <td class="partition" colspan="3">已有的标签</td>
                </tr>
                <tr class="header">
                    <td width="20">&nbsp;</td>
                    <td>日期</td>
                    <td width="100" align="center">信息数</td>
                </tr>
                $if posts.totalrecords > 0:
                    $for post in posts.result:
                        <tr>
                            <td>&nbsp;</td>
                            <td><a href="$config.ADMIN_DIR/discount/top10/edit/$post.date_index">第 <strong>$post.date_index</strong> 期</a></td>
                            <td align="center">$len(post.discount_info_ids.split(','))</td>
                        </tr>
                    <tr>
                        <td colspan="3" align="right">$:pager</td>
                    </tr>
                $else:
                    <tr>
                        <th colspan="3" class="partition">尚未添加设置TOP30</th>
                    </tr>
            </table>
        </td>
    </tr>
</table>


$:render.admin.footer()
